/*
#Copyright (c) 2013, Philippe Bordron <philippe.bordron@gmail.com>
#
# This file is part of SIPPER.
#
# DCC is free software: you can redistribute it and/or modify
# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DCC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU LESSER GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# along with SIPPER.  If not, see <http://www.gnu.org/licenses/>
*/
package combi.sipper.modeling;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

public abstract class Genome<G> extends ArrayList<G> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Map<G, Integer> rank;

	public Genome(List<G> genesSequence)
	{
		super(genesSequence);
		int r = 0;
		for (G g : genesSequence)
		{
			rank.put(g, r);
			r++;
		}

	}

	public int getRank(G gene)
	{ 
		Integer result =  rank.get(gene);
		if (result != null)
		{
			return result;
		}
		return -1;
	}

	public Collection<Integer> getRanks(Collection<G> genes)
	{
		ArrayList<Integer> ranks = new ArrayList<Integer>(genes.size());
		for (G g : genes)
		{
			ranks.add(this.getRank(g));
		}
		return ranks;
	}
	
	public abstract List<G> smallestInducedIntervalOfGenes(Collection<G> genes);
	
	public abstract double sizeOfSmallestInducedIntervalOGenes(Collection<G> genes);
	
	public void clear()
	{
		rank.clear();
		super.clear();
	}
}
